package com.item.yxlottery.yxlottery.adapter;

/*
 *------------------------------
 * @创建者      Administrator
 * @创建时间    2016/12/22 16:09
 * @文件描述    查看双色球已开奖号码的可折叠adapter
 *------------------------------
 */

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.item.yxlottery.yxlottery.R;
import com.item.yxlottery.yxlottery.bean.OpenSsqLotteryBean;
import com.item.yxlottery.yxlottery.bean.SsqBonusDetailBean;
import com.item.yxlottery.yxlottery.views.AutoTableLayout;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExpandableItemAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;
    private Context mContext;

    public ExpandableItemAdapter(Context context, List<MultiItemEntity> data) {
        super(data);
        mContext = context;
        addItemType(TYPE_LEVEL_0, R.layout.item_lottery_openssq);
        addItemType(TYPE_LEVEL_1, R.layout.item_lottery_ssqbounsdetail);
    }

    @Override
    protected void convert(final BaseViewHolder holder, MultiItemEntity item) {
        switch (holder.getItemViewType()) {
            case TYPE_LEVEL_0://第一级
                final OpenSsqLotteryBean lottery = (OpenSsqLotteryBean) item;
                String[] number = lottery.getNumber().split(",");
                View view = holder.getView(R.id.tv_openssq_nper);
                holder.setText(R.id.tv_openssq_nper, lottery.getNper())//期数
                        .setText(R.id.tv_openssq_time, lottery.getTime());//时间
                ((TextView) (holder.getView(R.id.tv_openssq_red1).findViewById(R.id.tv_item_openlottery_redball))).setText(number[0]);//红一
                ((TextView) (holder.getView(R.id.tv_openssq_red2).findViewById(R.id.tv_item_openlottery_redball))).setText(number[1]);//红二
                ((TextView) (holder.getView(R.id.tv_openssq_red3).findViewById(R.id.tv_item_openlottery_redball))).setText(number[2]);//红三
                ((TextView) (holder.getView(R.id.tv_openssq_red4).findViewById(R.id.tv_item_openlottery_redball))).setText(number[3]);//红四
                ((TextView) (holder.getView(R.id.tv_openssq_red5).findViewById(R.id.tv_item_openlottery_redball))).setText(number[4]);//红五
                ((TextView) (holder.getView(R.id.tv_openssq_red6).findViewById(R.id.tv_item_openlottery_redball))).setText(number[5]);//红六
                ((TextView) (holder.getView(R.id.tv_openssq_blue).findViewById(R.id.tv_item_openlottery_blueball))).setText(number[6]);//蓝
                final ImageView ivArrow = holder.getView(R.id.iv_openssq_arrow);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        int pos = holder.getAdapterPosition();
                        Logger.d(pos);
                        if (lottery.isExpanded()) {
                            ivArrow.setImageResource(R.drawable.downarrow);
                            collapse(pos);
                        } else {//打开
                            ivArrow.setImageResource(R.drawable.uparrow);
                            expandAll(pos, true, true);
                        }
                    }
                });
                break;
            case TYPE_LEVEL_1://第二级
                SsqBonusDetailBean detail = (SsqBonusDetailBean) item;
                ArrayList<String> strings = new ArrayList<>();
                strings.add("奖项");
                strings.add("注数");
                strings.add("奖金(元)  ");
                strings.add("一等奖");
                strings.add(detail.getFrist());
                strings.add(detail.getFristAmount());
                strings.add("二等奖");
                strings.add(detail.getSecond());
                strings.add(detail.getSecondAmount());
                strings.add("三等奖");
                strings.add(detail.getThird());
                strings.add(detail.getThirdAmount());
                strings.add("四等奖");
                strings.add(detail.getFourth());
                strings.add(detail.getFourthAmount());
                strings.add("五等奖");
                strings.add(detail.getFifth());
                strings.add(detail.getFifthAmount());
                strings.add("六等奖");
                strings.add(detail.getSixth());
                strings.add(detail.getSixthAmount());
                strings.add("一等奖复式加奖");
                strings.add(detail.getSeventh());
                strings.add(detail.getSeventhAmount());
                strings.add("六等奖复式加奖");
                strings.add(detail.getEighth());
                strings.add(detail.getEighthAmount());

                AutoTableLayout atlTable = holder.getView(R.id.atl_ssqbonusdetail_table);
                ArrayList<Map<String, Object>> dataList = new ArrayList<>();
                Map<String, Object> map = null;
                for (int i = 0; i < strings.size(); i++) {
                    map = new HashMap();
                    map.put("title", strings.get(i));
                    dataList.add(map);
                }
                atlTable.setAdapter(new TableAdapter(mContext, dataList), 3);
                break;
        }
    }
}
